<template>
	<view class="auth">
		<view class="info">
			<view class="line">
				<view class="l">姓名：</view>
				<input type="text" class="r" v-model="info.name" />
			</view>
			<view class="line">
				<view class="l">手机号：</view>
				<input type="text" class="r" v-model="info.mobile" />
			</view>
		</view>
		<!-- <view class="btn" @click="save" v-if="service == 0">提交</view>
		<view class="btn" @click="save" v-else-if="status === -1">审核失败，重新提交</view>
		<view class="btn"  v-else-if="status === 1 ">审核通过</view>
		<view class="btn" v-else-if="status === 0 ">待审核</view> -->
		<view class="btn" @click="save">下一步</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				deletable: false,
				info: {
					name: '',
					mobile: '',
					zimage: '',
					fimage: '',

				},
				fileList2: [],
				fileList1: [],
				status: '',
				service:uni.getStorageSync('service')
			};
		},
		onLoad() {
			this.getInfo()
		},
		methods: {
			save() {
				if(this.info.name === '' ) {
					this.$u.toast('请输入姓名');
					return
				}
				if(!uni.$u.test.mobile(this.info.mobile)) {
					this.$u.toast('请输入正确的手机号');
					return
				}
				this.authTo('pages/newissue/skill?info=' + JSON.stringify(this.info))
				return
				
				uni.$u.http.post('/ident', {
					type: 'send',
					...this.info
				}).then(res => {
					if (res.code === 1) {
						this.$u.toast(res.msg);
						setTimeout(() => {
							this.back()
						},1000)
					}
				}).catch((res) => {

				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				console.log(event.name)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					console.log(result)
					if (result) {
						let item = this[`fileList${event.name}`][fileListLen]
						this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result
						}))
						fileListLen++
					} else {
						this[`fileList${event.name}`].splice(fileListLen, 1)
					}

				}
				console.log(this[`fileList${event.name}`])
			},
			uploadFilePromise(url) {
				let that = this
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: that.Upload.uploadurl, // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							type: 'image',
							token: uni.getStorageSync('token')
						},
						success: (res) => {
							let data = JSON.parse(res.data)
							if (res.statusCode === 200 && data.code === 1 && data.data) {
								resolve(data.data.url)
							} else {
								resolve()
							}
						}
					});
				})
			},
			getInfo() {
				uni.$u.http.post('/ident').then(res => {
					if (res.code === 1) {
						if(res.data) {
							this.info.name = res.data.name
							this.info.mobile = res.data.mobile
							this.info.zimage = res.data.zimage
							this.info.fimage = res.data.fimage
							this.status = res.data.status
							this.fileList1 = [
								{
									fullurl: res.data.zimage,
									url: this.oss(res.data.zimage),
								}
							]
							this.fileList2 = [
								{
									fullurl: res.data.fimage,
									url: this.oss(res.data.fimage)
								}
							]
							console.log(this.fileList1)
								console.log(this.fileList2)
						} else {
							this.status = ''
						}
					}
				}).catch((res) => {
					
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F6F6F6;
	}

	.auth {
		background: linear-gradient(to bottom, #FFC141, #F6F6F6);
		background-size: 750rpx 500rpx;
		background-repeat: no-repeat;
		padding-top: 50rpx;

		.btn {
			background: linear-gradient(to right, #FFDF41, #FFC141);
			height: 88rpx;
			border: 44rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 50rpx auto 0;
			width: 590rpx;
			border-radius: 44rpx;
		}

		.info {
			background: #FFFFFF;
			margin: 0 20rpx;
			border-radius: 20rpx;
			padding: 0 20rpx 20rpx;

			.line {
				height: 100rpx;
				display: flex;
				align-items: center;
				border-bottom: 1px solid #F6F6F6;

				.l {
					color: #575859;
					font-size: 32rpx;
				}

				.r {
					flex: 1;
				}
			}

			.box {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				height: 230rpx;
				width: 510rpx;
				margin: 20rpx auto;
				border: 1px solid #FFCE54;
				border-radius: 20rpx;

				.cover {}

				.icon {
					width: 51rpx;
					height: 49rpx;
				}

				.word {
					color: #FF8007;
					font-size: 30rpx;
					margin-top: 20rpx;
				}
			}
		}
	}
</style>
